/********************************************************************************
 * Copyright(c) 2020-2025 BST All rights reserved.
 * - Filename
 * - Author
 * - Version V1.0.0
 * - Date    2025/07/230
 * - Brief
 * - FunctionList:
 ******************************************************************************
 * History:
 *
 *
 *
 ******************************************************************************
 */
#pragma once

#include <condition_variable>
#include <deque>
#include <mutex>

#include "AEyeSDKConfig.hpp"
#include "Lidar.hpp"
#include "PointCloudFrame.hpp"
#include "Sensor.hpp"
#include "TimeUtil.h"

namespace lidar {

class ApolloLidarAdapter : public lidar::Lidar {
 public:
  ApolloLidarAdapter(const std::string &interface, const std::string &ip,
                        const uint32_t &id);
  ~ApolloLidarAdapter();
  void start(std::function<void(std::shared_ptr<lpc::LidarProtoPointCloud> &&)>)
      override;
  void stop() override;

 protected:
  const std::string _interface;
  const std::string _ip;
  const uint32_t _id;

 private:
  bool _isExit{true};
  TimeUtil::FpsCalc _fps{};

  std::shared_ptr<aeye::Sensor> _lidar{nullptr};
  std::shared_ptr<std::thread> _packageThread{nullptr};
  std::mutex _mtx;
  std::condition_variable _condition;
  std::deque<std::shared_ptr<lpc::LidarProtoPointCloud>> _lidarFrameDeque{};
  void processLoop(
      const std::function<void(std::shared_ptr<lpc::LidarProtoPointCloud> &&)>
          &callback);
  void pointsCallback(aeye::PointCloudFrame &&originalFrame);
};
}  // namespace lidar